<?php
	class ModHighscores
	{
		public function index()
		{
			viewLayer::$var->reqAccess = configLayer::get('hs_gm_access');
			if( !$_REQUEST['skill'] )
			{
				viewLayer::$var->skillType = "experience";
				$this->assignVariables( "experience" );
				viewLayer::render('highscores');
				return false;
			}
			
			$this->assignVariables( strtolower($_REQUEST['skill']) );
			viewLayer::$var->skillType = strtolower($_REQUEST['skill']);
			viewLayer::render('highscores');
			
		}
		
		private function assignVariables( $type )
		{
			$p = new OTS_Players_List;
			$p->setLimit( intval( configLayer::get('hs_players_limit') ) );
			
			switch( $type )
			{
				case "fist":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 0 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "club":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 1 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "axe":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 2 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "sword":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 3 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "distance":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 4 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "fishing":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 6 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "shield":
					$filter = new OTS_SQLFilter;
					$filter->addFilter( new OTS_SQLField('id', 'players'), new OTS_SQLField( 'player_id', 'player_skills' ) );
					$filter->addFilter( new OTS_SQLField('skillid', 'player_skills'), 5 );
					$p->setFilter( $filter );
					$p->orderBy( new OTS_SQLField( 'value', 'player_skills' ), POT::ORDER_DESC );
				break;
				
				case "magiclevel":
					$p->orderBy( 'maglevel', POT::ORDER_DESC );
				break;
				
				case "experience":
					$p->orderBy( 'experience', POT::ORDER_DESC );
				break;
			}
			
			viewLayer::$var->plist = $p;
		}
	}
?>